package com.bxl.chooser.factory;

import com.bxl.chooser.context.ChooserContext;
import com.bxl.netty.rpc.common.context.Context;
import com.bxl.netty.rpc.common.util.HandlerFactory;

import java.lang.reflect.Constructor;

/**
 * <>
 *
 * @author baixl
 * @date 2021/3/25
 */
public class HandlerAdapterFactory extends HandlerFactory<Context> {

    public HandlerAdapterFactory(Class clazz) {
        super(clazz);
    }

    @Override
    public <T> T getBean(Context context) {
        try {
            Constructor constructor = clazz.getConstructor(Context.class);
            return (T)constructor.newInstance(context);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
